package com.ws.gold.scheduled;

import cn.hutool.core.util.StrUtil;
import com.ws.gold.domain.AiAnalysis;
import com.ws.gold.service.AiAnalysisService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ws
 * @create 2025/6/29
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/task")
public class CountTask {

    private final AiAnalysisService aiAnalysisService;

    @Scheduled(cron = "0 20 14 * * ?")
    @GetMapping("/aiAnalysis")
    public void aiAnalysis() {
        log.info("ai分析定时任务开始");
        String aiData = aiAnalysisService.getAiData();
        if (StrUtil.isNotEmpty(aiData)) {
            aiAnalysisService.save(AiAnalysis.builder().content(aiData).build());
        }
        log.info("ai分析定时任务结束");
    }

}
